function userNameCheck(){
	var $userError = $("#userName").parent().find(".userNum-error");
	var $userName = $("#userName").val();
	$("#userName").on("focus",function(){
		$(this).css("border","1px solid #3FB838")
		$(this).parent().find(".userNum-error").css("display","none");
	});
	if ($userName == "") {//判断登陆用户名为空
		$userError.css("display","block");
		$("#useNum-error-content").html('邮箱/手机号/用户名');
		$("#userName").css("border","1px solid #de3a39")
	} else{
		passwordL($userName);
	};
}
function passwordL($userName,ischeckNum){
	var isLogin = "isLogin";//判断用户是否登陆
	var myUserName = "myUserName";//用户名所对应的key值
	var myPwd = "myPwd";//密码所对应的key值
	
	var $passwordError = $("#password").parent().find(".userNum-error");
	var $password = $("#password").val();
	$("#password").on("focus",function(){
		$(this).css("border","1px solid #3FB838")
		$(this).parent().find(".userNum-error").css("display","none");
	});
	if ($password == "") {//判断登陆用户名为空
		$passwordError.css("display","block");
		$("#password-error-content").html('请输入密码');
		$("#password").css("border","1px solid #de3a39")
	} else{
		if ($password.length<6 || $password.length>15) {
			$passwordError.css("display","block");
			$("#password-error-content").html('密码长度只能在6-16位字符之间');
			$(this).css("border","1px solid #de3a39")
		}else{
			$(".check-num").css("display","block");
			checkYanZhengMa($userName);
			if(ischeckNum){
				if($userName != getCookie(myUserName)){
					$("#userName").parent().find(".userNum-error").css("display","block");
					$("#useNum-error-content").html('您输入的账户名不存在，请核对后重新输入');
					$("#userName").css("border","1px solid #de3a39");
				}else{
					$("#userName").parent().find(".ok").css("display","block");
					if($password != getCookie(myPwd)){
						$passwordError.css("display","block");
						$("#password-error-content").html('您输入的密码不正确，请核对后重新输入');
						$(this).css("border","1px solid #de3a39");
				
					}else{
						$("#password").parent().find(".ok").css("display","block");
						updateCookie(isLogin,"1");
						window.location = "../index.html";
					}
				}
			}
		}
	};	
}
	//验证码的验证
function checkYanZhengMa($userName){
	var checkNum = {
		img:['../img/yanzhengma0.png','../img/yanzhengma1.png','../img/yanzhengma2.png'],
		num:['n2dk','xth9','61wm']
	};//用对象将数据存起来模拟动态生成验证码
	var $c = 0;
//	console.log(checkNum.img)
	$("#check-num").on("focus",function(){
		$(this).css("border","1px solid #3FB838")
		$(this).parent().find(".userNum-error").css("display","none");
	});
	$("#check-num").on("blur",function(){
		var $checkNum = $(this).val();
		$checkNum =$checkNum.toLocaleLowerCase();//不区分大小写
//		console.log($checkNum)
		var checkImg = $(this).parent().find("img").attr("src");
//		console.log(checkImg)
		if ($checkNum == "") {
			$(this).parent().find(".userNum-error").css("display","none");
			$(this).css("border","1px solid #cfcfd1")
		}else{
//			console.log($c)
			if($checkNum != checkNum.num[$c]){
				$(this).parent().find(".userNum-error").css("display","block");
				$(this).css("border","1px solid #3FB838")
			}else{
				$(this).parent().find(".ok").css("display","block");
				$(this).css("border","1px solid #3FB838");
				passwordL($userName,true) 
			};
		};
	});
	$(".yanzhengma-text").find("a").on("click",function(){//切换验证码的事件
		$(this).parent().parent().find(".ok").css("display","none");
		isCheckNum = false;
		if($c>2){
			$c = 0;
		}
		$(this).parent().parent().find('img').attr("src",checkNum.img[$c+1]);
		$c++;
	});
}


$(function(){
	$("#login-base").load('lrbase.html #denglu');
	$("#footer").load("lrbase.html #footer1");
	//登陆
	$("#login-success").on("click",function(){
		//用户名检测
		userNameCheck();
	});
	//记住密码
	var isRememberPassword = 1;
	$(".remember_password1").on("click",function(){
		if(isRememberPassword%2 == 0){
			$(this).css("background","url(../img/login_bg.png) no-repeat -406px -197px")
		}else{
			$(this).css("background","url(../img/login_bg.png) no-repeat -406px -219px")
		}
		isRememberPassword++;
	})
})



